package com.example.demo.bean;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import net.minidev.json.annotate.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;


import javax.persistence.*;
import java.util.List;

/**
 * @Author:linchong
 * @CreateTime:2020-03-30 10:51
 * @Description:区域
 */
@Getter
@Setter
@Entity
@Table(name = "area")
@NamedEntityGraph(name = "Area.Graph", attributeNodes = {@NamedAttributeNode("children")})
public class Area {

	@Id
	@GeneratedValue(generator = "UUID")
	@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
	private String id;

	/**
	 * 区域名
	 */
	private String name;

	/**
	 * 一个区域信息下面很多子区域 (多级) 比如 : 广东省 (子) 区域 : 广州市 (孙)子区域 : 天河区
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parent_id")
	@JsonIgnore
	private Area parent;

	@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
	private List<Area> children;



}
